
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>016异常 · 书名</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="作者">
        <meta name="identifier" content="图书编号" scheme="ISBN">
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-intopic-toc/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="017集合.html" />
    
    
    <link rel="prev" href="015接口.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    书名
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Books</li>
        
        
    
        <li class="chapter " data-level="2.1" >
            
                <span>
            
                    
                    Java
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="001环境变量.html">
            
                <a href="001环境变量.html">
            
                    
                    001环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="002Java初体验.html">
            
                <a href="002Java初体验.html">
            
                    
                    002Java初体验
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="003变量命名及数据类型.html">
            
                <a href="003变量命名及数据类型.html">
            
                    
                    003变量命名及数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="004运算符.html">
            
                <a href="004运算符.html">
            
                    
                    004运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5" data-path="005选择结构.html">
            
                <a href="005选择结构.html">
            
                    
                    005选择结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6" data-path="006循环结构.html">
            
                <a href="006循环结构.html">
            
                    
                    006循环结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7" data-path="007数组.html">
            
                <a href="007数组.html">
            
                    
                    007数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.8" data-path="008类和对象方法.html">
            
                <a href="008类和对象方法.html">
            
                    
                    008类和对象方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.9" data-path="009构造方法.html">
            
                <a href="009构造方法.html">
            
                    
                    009构造方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.10" data-path="010封装与关键字static.html">
            
                <a href="010封装与关键字static.html">
            
                    
                    010封装与关键字Static
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.11" data-path="011 继承.html">
            
                <a href="011 继承.html">
            
                    
                    011 继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.12" data-path="012方法重写.html">
            
                <a href="012方法重写.html">
            
                    
                    012方法重写
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.13" data-path="013多态.html">
            
                <a href="013多态.html">
            
                    
                    013多态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.14" data-path="014抽象类抽象方法.html">
            
                <a href="014抽象类抽象方法.html">
            
                    
                    014抽象类抽象方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.15" data-path="015接口.html">
            
                <a href="015接口.html">
            
                    
                    015接口
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.1.16" data-path="016异常.html">
            
                <a href="016异常.html">
            
                    
                    016异常
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.17" data-path="017集合.html">
            
                <a href="017集合.html">
            
                    
                    017集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.18" data-path="017集合2.html">
            
                <a href="017集合2.html">
            
                    
                    017集合2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.19" data-path="018泛型.html">
            
                <a href="018泛型.html">
            
                    
                    018泛型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.20" data-path="019Collections算法类.html">
            
                <a href="019Collections算法类.html">
            
                    
                    019Collections算法类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.21" data-path="020枚举.html">
            
                <a href="020枚举.html">
            
                    
                    020枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.22" data-path="021包装类.html">
            
                <a href="021包装类.html">
            
                    
                    021包装类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.23" data-path="022常用类.html">
            
                <a href="022常用类.html">
            
                    
                    022常用类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.24" data-path="023File类.html">
            
                <a href="023File类.html">
            
                    
                    023File类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.25" data-path="024IO流.html">
            
                <a href="024IO流.html">
            
                    
                    024IO流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.26" data-path="025多线程.html">
            
                <a href="025多线程.html">
            
                    
                    025多线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.27" data-path="025多线程线程池.html">
            
                <a href="025多线程线程池.html">
            
                    
                    025多线程线程池
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.28" data-path="026网络编程Socket.html">
            
                <a href="026网络编程Socket.html">
            
                    
                    026网络编程Socket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.29" data-path="027XML解析.html">
            
                <a href="027XML解析.html">
            
                    
                    027XML解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.30" data-path="028 注解.html">
            
                <a href="028 注解.html">
            
                    
                    028 注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.31" data-path="029 Lambda表达式.html">
            
                <a href="029 Lambda表达式.html">
            
                    
                    029 Lambda表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.32" data-path="029 反射.html">
            
                <a href="029 反射.html">
            
                    
                    029 反射
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2" >
            
                <span>
            
                    
                    Mybatis
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="../mybatis/MyBatis.html">
            
                <a href="../mybatis/MyBatis.html">
            
                    
                    MyBatis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1.1" >
            
                <span>
            
                    
                    MyBatis
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" >
            
                <span>
            
                    
                    Mysql
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="../mysql/01 SQL通用语法.html">
            
                <a href="../mysql/01 SQL通用语法.html">
            
                    
                    01 SQL通用语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="../mysql/02 DDL.html">
            
                <a href="../mysql/02 DDL.html">
            
                    
                    02 DDL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.3" data-path="../mysql/03 DML.html">
            
                <a href="../mysql/03 DML.html">
            
                    
                    03 DML
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.4" data-path="../mysql/04 DQL.html">
            
                <a href="../mysql/04 DQL.html">
            
                    
                    04 DQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.5" data-path="../mysql/05 DCL.html">
            
                <a href="../mysql/05 DCL.html">
            
                    
                    05 DCL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.6" data-path="../mysql/06 函数.html">
            
                <a href="../mysql/06 函数.html">
            
                    
                    06 函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.7" data-path="../mysql/07 约束.html">
            
                <a href="../mysql/07 约束.html">
            
                    
                    07 约束
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.8" data-path="../mysql/08 多表查询.html">
            
                <a href="../mysql/08 多表查询.html">
            
                    
                    08 多表查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.9" data-path="../mysql/09 事务.html">
            
                <a href="../mysql/09 事务.html">
            
                    
                    09 事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.10" data-path="../mysql/999zzz.html">
            
                <a href="../mysql/999zzz.html">
            
                    
                    999zzz
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.11" data-path="../mysql/MySql.html">
            
                <a href="../mysql/MySql.html">
            
                    
                    MySql
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.12" data-path="../mysql/sql.html">
            
                <a href="../mysql/sql.html">
            
                    
                    Sql
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" >
            
                <span>
            
                    
                    Spring
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../spring/spring.html">
            
                <a href="../spring/spring.html">
            
                    
                    Spring
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" >
            
                <span>
            
                    
                    SpringMVC
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="../springMVC/springMVC.html">
            
                <a href="../springMVC/springMVC.html">
            
                    
                    SpringMVC
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.6" >
            
                <span>
            
                    
                    整合
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.6.1" data-path="../整合/Mybatis框架.html">
            
                <a href="../整合/Mybatis框架.html">
            
                    
                    Mybatis框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.2" data-path="../整合/SpringBoot.html">
            
                <a href="../整合/SpringBoot.html">
            
                    
                    SpringBoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.3" data-path="../整合/springmvc框架.html">
            
                <a href="../整合/springmvc框架.html">
            
                    
                    Springmvc框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.4" data-path="../整合/spring框架.html">
            
                <a href="../整合/spring框架.html">
            
                    
                    Spring框架
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >016异常</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="java-&#x7684;&#x5F02;&#x5E38;&#x5904;&#x7406;-5-&#x4E2A;&#x5173;&#x952E;&#x5B57;&#x6765;&#x5B9E;&#x73B0;"><strong>java &#x7684;&#x5F02;&#x5E38;&#x5904;&#x7406; 5 &#x4E2A;&#x5173;&#x952E;&#x5B57;&#x6765;&#x5B9E;&#x73B0;</strong></h2>
<blockquote>
<p>try, catch, finally, throw, throws</p>
</blockquote>
<ul>
<li>&#x6355;&#x83B7;&#x5F02;&#x5E38;<ul>
<li>try &#x6267;&#x884C;&#x53EF;&#x80FD;&#x4EA7;&#x751F;&#x5F02;&#x5E38;&#x7684;&#x4EE3;&#x7801;</li>
<li>catch &#x6355;&#x83B7;&#x5F02;&#x5E38;</li>
<li>finally &#x65E0;&#x8BBA;&#x662F;&#x5426;&#x53D1;&#x751F;&#x4E00;&#x6B21;,&#x4EE3;&#x7801;&#x603B;&#x80FD;&#x6267;&#x884C;</li>
</ul>
</li>
<li>&#x58F0;&#x660E;&#x5F02;&#x5E38;<ul>
<li>throws &#x58F0;&#x660E;&#x65B9;&#x6CD5;&#x53EF;&#x80FD;&#x8981;&#x629B;&#x51FA;&#x7684;&#x5404;&#x79CD;&#x5F02;&#x5E38;</li>
</ul>
</li>
<li>&#x629B;&#x51FA;&#x5F02;&#x5E38;<ul>
<li>throw &#x624B;&#x52A8;&#x629B;&#x51FA;&#x5F02;&#x5E38;</li>
</ul>
</li>
</ul>
<h2 id="&#x6355;&#x83B7;&#x5F02;&#x5E38;">&#x6355;&#x83B7;&#x5F02;&#x5E38;</h2>
<p><strong>try-catch&#x5757;</strong></p>
<p>&#x4F7F;&#x7528;try-catch&#x5757;&#x6355;&#x83B7;&#x5F02;&#x5E38;</p>
<blockquote>
<p>&#x5728; try &#x4EE3;&#x7801;&#x5757;&#x4E2D;&#x6355;&#x83B7;&#x5F02;&#x5E38;, &#x5728; catch &#x4E2D;&#x5904;&#x7406;&#x5F02;&#x5E38;</p>
</blockquote>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">method</span><span class="hljs-params">()</span></span>{
    <span class="hljs-keyword">try</span>{
        <span class="hljs-comment">// &#x4EE3;&#x7801;&#x6BB5;(&#x6B64;&#x5904;&#x4E0D;&#x4F1A;&#x4EA7;&#x751F;&#x5F02;&#x5E38;)</span>
    } <span class="hljs-keyword">catch</span> (&#x5F02;&#x5E38;&#x7C7B;&#x578B; ex) {
        <span class="hljs-comment">// &#x5F02;&#x5E38;&#x8FDB;&#x884C;&#x5904;&#x7406;&#x7684;&#x4EE3;&#x7801;&#x6BB5;</span>
    }
    <span class="hljs-comment">// &#x4EE3;&#x7801;&#x6BB5;</span>
}
</code></pre>
<p><strong>&#x5728; catch &#x5757;&#x4E2D;&#x5904;&#x7406;&#x5F02;&#x5E38;</strong></p>
<ul>
<li><p>&#x52A0;&#x5165;&#x7528;&#x6237;&#x81EA;&#x5B9A;&#x4E49;&#x5904;&#x7406;&#x4FE1;&#x606F;</p>
<p>System.err.println(&quot;&#x51FA;&#x73B0;&#x9519;&#x8BEF;: XXXX&quot;);</p>
</li>
<li><p>&#x8C03;&#x7528;&#x65B9;&#x6CD5;&#x8F93;&#x51FA;&#x5F02;&#x5E38;&#x4FE1;&#x606F;</p>
<p>e.printStackTrace();</p>
</li>
<li><p>&#x5F02;&#x5E38;&#x5BF9;&#x8C61;&#x5E38;&#x7528;&#x7684;&#x65B9;&#x6CD5;</p>
<p>| &#x65B9;&#x6CD5;                   | &#x8BF4;&#x660E;                                                   |
| :--------------------- | :----------------------------------------------------- |
| void printStackTrace() | &#x8F93;&#x51FA;&#x5F02;&#x5E38;&#x7684;&#x5806;&#x6808;&#x4FE1;&#x606F;                                     |
| String getMessage();   | &#x8FD4;&#x56DE;&#x5F02;&#x5E38;&#x4FE1;&#x606F;&#x63CF;&#x8FF0;&#x5B57;&#x7B26;&#x4E32;,&#x662F;printStackTrace()&#x4FE1;&#x606F;&#x7684;&#x4E00;&#x90E8;&#x5206; |</p>
</li>
</ul>
<p><strong>&#x5728; try-catch &#x5757;&#x4E2D;&#x4ECB;&#x5165; finally</strong></p>
<blockquote>
<p>finally &#x5757;&#x4E2D; &#x65E0;&#x8BBA;&#x662F;&#x5426;&#x53D1;&#x751F;&#x5F02;&#x5E38;&#x90FD;&#x6267;&#x884C;</p>
<p>&#x4E0D;&#x6267;&#x884C;&#x7684;&#x552F;&#x4E00;&#x60C5;&#x51B5;: &#x5728; try &#x5757;&#x4E2D; &#x548C; catch &#x5757;&#x4E2D; &#x6709;&#x4E2D;&#x65AD;&#x7A0B;&#x5E8F;,&#x9000;&#x51FA; Java &#x865A;&#x62DF;&#x673A;&#x7684;&#x8BED;&#x53E5; ( System.exit(1) )</p>
</blockquote>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">public</span> coid <span class="hljs-title">method</span><span class="hljs-params">()</span></span>{
    <span class="hljs-keyword">try</span> {
        <span class="hljs-comment">// &#x4EE3;&#x7801;1</span>
        <span class="hljs-comment">// &#x4EA7;&#x751F;&#x5F02;&#x5E38;&#x7684;&#x4EE3;&#x7801;&#x6BB5;2</span>
    } <span class="hljs-keyword">catch</span> (&#x5F02;&#x5E38;&#x7C7B;&#x578B; ex) {
        <span class="hljs-comment">// &#x5BF9;&#x5F02;&#x5E38;&#x8FDB;&#x884C;&#x5904;&#x7406;&#x7684;&#x4EE3;&#x7801;&#x6BB5;3</span>
        <span class="hljs-keyword">return</span>;
    } <span class="hljs-keyword">finally</span>{
        <span class="hljs-comment">// &#x4EE3;&#x7801;&#x6BB5;4</span>
        <span class="hljs-comment">// &#x5373;&#x4F7F; try-catch &#x4E2D;&#x6709;return,&#x4E5F;&#x4F1A;&#x6267;&#x884C; finally &#x4E2D;&#x7684;&#x4EE3;&#x7801;</span>
    }
}
</code></pre>
<p><strong>&#x591A;&#x91CD;catch</strong>
&#x5F15;&#x53D1;&#x591A;&#x79CD;&#x7C7B;&#x578B;&#x7684;&#x5F02;&#x5E38;</p>
<ul>
<li>&#x6392;&#x5217; catch &#x8BED;&#x53E5;&#x7684;&#x987A;&#x5E8F;: &#x5148;&#x5B50;&#x7C7B;&#x540E;&#x7236;&#x7C7B;</li>
<li>&#x53D1;&#x751F;&#x5F02;&#x5E38;&#x65F6;&#x6309;&#x987A;&#x5E8F;&#x9010;&#x4E2A;&#x5339;&#x914D;</li>
<li>&#x53EA;&#x6267;&#x884C;&#x7B2C;&#x4E00;&#x4E2A;&#x4E0E;&#x5F02;&#x5E38;&#x7C7B;&#x578B;&#x5339;&#x914D;&#x7684; catch &#x8BED;&#x53E5;</li>
</ul>
<p><strong>&#x5C0F;&#x7ED3;</strong></p>
<ol>
<li>try-catch-finally &#x7ED3;&#x6784;&#x4E2D; try &#x8BED;&#x53E5;&#x5757;&#x662F;&#x5FC5;&#x987B;&#x7684;, catch finally&#x8BED;&#x53E5;&#x5757;&#x53EF;&#x9009;, &#x4F46;&#x4E24;&#x8005;&#x81F3;&#x5C11;&#x51FA;&#x73B0;&#x4E00;&#x6B21;</li>
<li>try-catch &#x4E2D;&#x5B58;&#x5728; return, finally&#x8FD8;&#x662F;&#x4F1A;&#x6267;&#x884C;</li>
<li>finally&#x5757;&#x4E2D;&#x552F;&#x4E00;&#x4E0D;&#x6267;&#x884C;&#x7684;&#x60C5;&#x51B5;: &#x5728;try-catch&#x4E2D;&#x51FA;&#x73B0; System.exit(1);</li>
</ol>
<h2 id="&#x5E38;&#x89C1;&#x7684;&#x5F02;&#x5E38;&#x7C7B;&#x578B;">&#x5E38;&#x89C1;&#x7684;&#x5F02;&#x5E38;&#x7C7B;&#x578B;</h2>
<table>
<thead>
<tr>
<th>&#x5F02;&#x5E38;&#x7C7B;&#x578B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>Exception</td>
<td>&#x5F02;&#x5E38;&#x5C42;&#x6B21;&#x7ED3;&#x6784;&#x7684;&#x7236;&#x7C7B;</td>
</tr>
<tr>
<td>ArithmeticException</td>
<td>&#x7B97;&#x672F;&#x9519;&#x8BEF;&#x60C5;&#x5F62;&#xFF0C;&#x5982;&#x4EE5;&#x96F6;&#x4F5C;&#x9664;&#x6570;</td>
</tr>
<tr>
<td>ArrayIndexOutOfBoundsException</td>
<td>&#x6570;&#x7EC4;&#x4E0B;&#x6807;&#x8D8A;&#x754C;</td>
</tr>
<tr>
<td>NullPointerException</td>
<td>&#x5C1D;&#x8BD5;&#x8BBF;&#x95EE; null &#x5BF9;&#x8C61;&#x6210;&#x5458;</td>
</tr>
<tr>
<td>ClassNotFoundException</td>
<td>&#x4E0D;&#x80FD;&#x52A0;&#x8F7D;&#x6240;&#x9700;&#x7684;&#x7C7B;</td>
</tr>
<tr>
<td>IllegalArgumentException</td>
<td>&#x65B9;&#x6CD5;&#x63A5;&#x6536;&#x5230;&#x975E;&#x6CD5;&#x53C2;&#x6570;</td>
</tr>
<tr>
<td>ClassCastException</td>
<td>&#x5BF9;&#x8C61;&#x5F3A;&#x5236;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x51FA;&#x9519;</td>
</tr>
<tr>
<td>NumberFormatException</td>
<td>&#x6570;&#x5B57;&#x683C;&#x5F0F;&#x8F6C;&#x6362;&#x5F02;&#x5E38;&#xFF0C;&#x5982;&#x628A;&quot;abc&quot;&#x8F6C;&#x6362;&#x6210;&#x6570;&#x5B57;</td>
</tr>
</tbody>
</table>
<h2 id="&#x58F0;&#x660E;&#x5F02;&#x5E38;">&#x58F0;&#x660E;&#x5F02;&#x5E38;</h2>
<blockquote>
<p>&#x5982;&#x679C;&#x5728;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x4F53;&#x4E2D;&#x629B;&#x51FA;&#x5F02;&#x5E38;,&#x5982;&#x4F55;&#x901A;&#x77E5;&#x8C03;&#x7528;&#x8005;</p>
<p>throws &#x58F0;&#x660E;&#x67D0;&#x4E2A;&#x65B9;&#x6CD5;&#x53EF;&#x80FD;&#x629B;&#x51FA;&#x7684;&#x5404;&#x79CD;&#x5F02;&#x5E38;,&#x591A;&#x4E2A;&#x5F02;&#x5E38;&#x7528;&#x9017;&#x53F7;&#x9694;&#x5F00;</p>
</blockquote>
<p>&#x65B9;&#x5F0F;1:&#x8C03;&#x7528;&#x8005;&#x5904;&#x7406;&#x5F02;&#x5E38;</p>
<p>&#x65B9;&#x5F0F;2:&#x8C03;&#x7528;&#x8005;&#x7EE7;&#x7EED;&#x7533;&#x660E;&#x5F02;&#x5E38;</p>
<pre><code>main()&#x65B9;&#x6CD5;&#x7533;&#x660E;&#x7684;&#x5F02;&#x5E38;&#x6709; Java &#x865A;&#x62DF;&#x673A;&#x5904;&#x7406;
</code></pre><h2 id="&#x629B;&#x51FA;&#x5F02;&#x5E38;">&#x629B;&#x51FA;&#x5F02;&#x5E38;</h2>
<p>&#x9664;&#x4E86;&#x7CFB;&#x7EDF;&#x81EA;&#x52A8;&#x629B;&#x51FA;&#x5F02;&#x5E38;, &#x6709;&#x4E9B;&#x95EE;&#x9898;&#x9700;&#x8981;&#x7A0B;&#x5E8F;&#x5458;&#x81EA;&#x884C;&#x629B;&#x51FA;&#x5F02;&#x5E38;</p>
<p>&#x4F7F;&#x7528;throw&#x629B;&#x51FA;&#x5F02;&#x5E38;</p>
<p>throw&#x4E0E;throws</p>
<table>
<thead>
<tr>
<th>throw</th>
<th>throws</th>
</tr>
</thead>
<tbody>
<tr>
<td>&#x751F;&#x6210;&#x5E76;&#x629B;&#x51FA;&#x5F02;&#x5E38;</td>
<td>&#x58F0;&#x660E;&#x65B9;&#x6CD5;&#x5185;&#x629B;&#x51FA;&#x5F02;&#x5E38;</td>
</tr>
<tr>
<td>&#x4F4D;&#x4E8E;&#x65B9;&#x6CD5;&#x4F53;&#x5185;&#x90E8;,&#x53EF;&#x4F5C;&#x4E3A;&#x5355;&#x72EC;&#x8BED;&#x53E5;&#x4F7F;&#x7528;</td>
<td>&#x5FC5;&#x987B;&#x8DDF;&#x5728;&#x65B9;&#x6CD5;&#x53C2;&#x6570;&#x5217;&#x8868;&#x540E;&#x9762;,&#x4E0D;&#x80FD;&#x5355;&#x72EC;&#x4F7F;&#x7528;</td>
</tr>
<tr>
<td>&#x629B;&#x51FA;&#x4E00;&#x4E2A;&#x5F02;&#x5E38;&#x5BF9;&#x8C61;, &#x4E14;&#x53EA;&#x80FD;&#x662F;&#x4E00;&#x4E2A;</td>
<td>&#x58F0;&#x660E;&#x629B;&#x51FA;&#x5F02;&#x5E38;&#x7C7B;&#x578B;,&#x53EF;&#x4EE5;&#x8DDF;&#x591A;&#x4E2A;&#x5F02;&#x5E38;</td>
</tr>
</tbody>
</table>
<h2 id="&#x81EA;&#x5B9A;&#x4E49;&#x5F02;&#x5E38;">&#x81EA;&#x5B9A;&#x4E49;&#x5F02;&#x5E38;</h2>
<p>&#x5F53; JDk &#x4E2D;&#x7684;&#x5F02;&#x5E38;&#x7C7B;&#x578B;&#x4E0D;&#x80FD;&#x6EE1;&#x8DB3;&#x7A0B;&#x5E8F;&#x7684;&#x9700;&#x6C42;&#x65F6;, &#x53EF;&#x4EE5;&#x81EA;&#x5B9A;&#x4E49;&#x5F02;&#x5E38;&#x7C7B;</p>
<p>&#x4F7F;&#x7528;&#x81EA;&#x5B9A;&#x4E49;&#x5F02;&#x5E38;&#x7C7B;&#x7684;&#x6B65;&#x9AA4;</p>
<ol>
<li>&#x5B9A;&#x4E49;&#x5F02;&#x5E38;&#x7C7B;---&gt; &#x7EE7;&#x627F;Throwable&#x7C7B; &#x7EE7;&#x627F; Exception &#x6216;&#x8005; RuntimeException</li>
<li>&#x7F16;&#x5199;&#x6784;&#x9020;&#x65B9;&#x6CD5;,&#x7EE7;&#x627F;&#x7236;&#x7C7B;&#x7684;&#x5B9E;&#x73B0;</li>
<li>&#x5B9E;&#x4F8B;&#x5316;&#x81EA;&#x5B9A;&#x4E49;&#x5F02;&#x5E38;&#x5BF9;&#x8C61;</li>
<li>&#x4F7F;&#x7528;throw&#x629B;&#x51FA;</li>
</ol>
<p><strong>&#x5F02;&#x5E38;&#x5904;&#x7406;&#x539F;&#x5219;</strong></p>
<ul>
<li>&#x5F02;&#x5E38;&#x5904;&#x7406;&#x4E0E;&#x6027;&#x80FD;</li>
<li>&#x5F02;&#x5E38;&#x53EA;&#x80FD;&#x7528;&#x4E8E;&#x975E;&#x6B63;&#x5E38;&#x72B6;&#x6001;</li>
<li>&#x4E0D;&#x8981;&#x5C06;&#x8FC7;&#x4E8E;&#x5E9E;&#x5927;&#x7684;&#x4EE3;&#x7801;&#x5757;&#x653E;&#x5728; try &#x4E2D;</li>
<li>&#x5728; catch &#x4E2D;&#x6307;&#x5B9A;&#x5177;&#x4F53;&#x7684;&#x5F02;&#x5E38;&#x7C7B;&#x578B;</li>
<li>&#x9700;&#x8981;&#x5BF9;&#x6355;&#x83B7;&#x7684;&#x5F02;&#x5E38;&#x505A;&#x5904;&#x7406;</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="015接口.html" class="navigation navigation-prev " aria-label="Previous page: 015接口">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="017集合.html" class="navigation navigation-next " aria-label="Next page: 017集合">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"016异常","level":"2.1.16","depth":2,"next":{"title":"017集合","level":"2.1.17","depth":2,"path":"books/java/017集合.md","ref":"books/java/017集合.md","articles":[]},"previous":{"title":"015接口","level":"2.1.15","depth":2,"path":"books/java/015接口.md","ref":"books/java/015接口.md","articles":[]},"dir":"ltr"},"config":{"plugins":["search-pro","code","back-to-top-button","theme-comscore","intopic-toc","flexible-alerts","expandable-chapters"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"intopic-toc":{"selector":".markdown-section h1, .markdown-section h2, .markdown-section h3, .markdown-section h4, .markdown-section h5, .markdown-section h6","mode":"nested","maxDepth":6,"isCollapsed":true,"isScrollspyActive":true,"visible":true,"label":"In this article"},"search-pro":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"back-to-top-button":{},"flexible-alerts":{"style":"callout","note":{"label":"Note","icon":"fa fa-info-circle","className":"info"},"tip":{"label":"Tip","icon":"fa fa-lightbulb-o","className":"tip"},"warning":{"label":"Warning","icon":"fa fa-exclamation-triangle","className":"warning"},"danger":{"label":"Attention","icon":"fa fa-ban","className":"danger"}},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"作者","lang":"zh-cn","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"isbn":"图书编号","variables":{},"title":"书名","gitbook":"*","description":"描述"},"file":{"path":"books/java/016异常.md","mtime":"2022-08-11T00:26:00.430Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-03-01T12:24:55.135Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/anchor.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/gumshoe.polyfills.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

